//
//  MAPYServerConnectNavView.swift
//  Mars Proxy
//
//  Created by PowerfullClean on 2023/10/20.
//

import UIKit

class MAPYServerConnectNavView: MAPYServersListNavView {
    override func mapy_initViews() {
        super.mapy_initViews()
        addSubview(mapy_connectButton)
        
        mapy_connectButton.snp.makeConstraints { make in
            make.centerY.equalTo(mapy_leftButton.snp.centerY)
            make.right.equalToSuperview().offset(-20)
            make.size.equalTo(CGSize(width: 24, height: 24))
        }
    }
    
    override func mapy_buttonClick(sender: UIButton) {
        if sender == mapy_connectButton {
            if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_connected {
                MAPYManager.mapy_manager.mapy_vpnStateClickType = .mapy_disConnect
            }else {
                MAPYManager.mapy_manager.mapy_vpnStateClickType = .mapy_connect
            }
            
            MAPYManager.mapy_manager.mapy_connectSmartAction()
            mapy_viewGetVController?.navigationController?.popToRootViewController(animated: true)
            return
        }
        super.mapy_buttonClick(sender: sender)
    }
    lazy var mapy_connectButton: UIButton = {
        let mapy_connectButton = UIButton()
        mapy_connectButton.setImage(UIImage(named: "mapy_nav_connect"), for: .normal)
        mapy_connectButton.addTarget(self, action: #selector(mapy_buttonClick(sender:)), for: .touchUpInside)
        return mapy_connectButton
    }()
}
